#include "sd.h"
Guest guset;//当前申请人
Guest list_guest[M];//申请列表
Admin admin;//当前管理员
Admin list_admin[N];//管理员列表
int n = 0;//代表现有管理员的数量
int m = 0;//代表现有的访客申请的数量

void gotoxy(int x, int y) {
	HANDLE hout;
	COORD cor;
	hout = GetStdHandle(STD_OUTPUT_HANDLE);
	cor.X = x;
	cor.Y = y;
	SetConsoleCursorPosition(hout, cor);
}

void hide() {
	HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cor_info = { 1,0 };
	SetConsoleCursorInfo(hout, &cor_info);
}

int menu()
{
	gotoxy(40, 12);
	printf("欢迎来到校外人员登记系统");
	gotoxy(43, 14);
	printf("1.访客登录");
	gotoxy(43, 16);
	printf("2.管理员登陆");
	gotoxy(43, 18);
	printf("3.关于");
	gotoxy(43, 20);
	printf("其他任意键退出");
	hide();
	char ch;
	int result = 0;
	ch = _getch();
	switch (ch) {
	case '1':
		result = 1; break;
	case '2':
		result = 2; break;
	case '3':
		result = 3; break;
	}
	system("cls");
	return result;
}

void about()
{
	gotoxy(43, 12);
	printf("杭州电子科技大学--程序设计综合实践");
	gotoxy(43, 14);
	printf("校园外来人员进出监控与管理系统");
	gotoxy(43, 18);
	printf("制作人员：湛辰铖，林宁宇");
	gotoxy(43, 20);
	printf("按任意键返回上级菜单");
	hide();
	char ch = _getch();
	system("cls");
}

void read()
{
	FILE* fp;
	errno_t err1, err2 = fopen_s(&fp, "C:\\Users\\acer\\source\\repos\\system_call\\guest.txt", "r");
	while (fp != EOF)
	{
		fscanf_s(fp, "%d ", &list_guest[m].is_team);
		fscanf_s(fp, "%s ", list_guest[m].name, 20);
		fscanf_s(fp, "%d ", &list_guest[m].sex);
		fscanf_s(fp, "%s ", list_guest[m].telephone, 20);
		fscanf_s(fp, "%s ", list_guest[m].id_number, 30);
		fscanf_s(fp, "%s ", list_guest[m].work, 50);
		fscanf_s(fp, "%s ", list_guest[m].car_number, 10);
		fscanf_s(fp, "%s ", list_guest[m].surety_name, 20);
		fscanf_s(fp, "%s ", list_guest[m].surety_phone, 20);
		fscanf_s(fp, "%d ", &list_guest[m].health_code);
		fscanf_s(fp, "%d ", &list_guest[m].health_cough);
		fscanf_s(fp, "%d ", &list_guest[m].in_danger_area);
		fscanf_s(fp, "%s ", list_guest[m].apply_in_time, 20);
		fscanf_s(fp, "%s ", list_guest[m].apply_out_time, 20);
		fscanf_s(fp, "%s ", list_guest[m].reason, 30);
		fscanf_s(fp, "%d ", &list_guest[m].apply_result);
		fscanf_s(fp, "%s ", list_guest[m].real_in_time, 20);
		fscanf_s(fp, "%s\n", list_guest[m].real_out_time, 20);
		if (list_guest[m].is_team == 0 || list_guest[m].name[0] == '\0') break;
		m++;
	}
	err1 = fclose(fp);
}

void write()
{
	FILE* fp;
	errno_t err1, err2 = fopen_s(&fp, "C:\\Users\\acer\\source\\repos\\system_call\\guest.txt", "w+");
	for (int i = 0; i < m; i++)
	{
		fprintf(fp, "%d ", list_guest[i].is_team);
		fprintf(fp, "%s ", list_guest[i].name, 20);
		fprintf(fp, "%d ", list_guest[i].sex);
		fprintf(fp, "%s ", list_guest[i].telephone, 20);
		fprintf(fp, "%s ", list_guest[i].id_number, 30);
		fprintf(fp, "%s ", list_guest[i].work, 50);
		fprintf(fp, "%s ", list_guest[i].car_number, 10);
		fprintf(fp, "%s ", list_guest[i].surety_name, 20);
		fprintf(fp, "%s ", list_guest[i].surety_phone, 20);
		fprintf(fp, "%d ", list_guest[i].health_code);
		fprintf(fp, "%d ", list_guest[i].health_cough);
		fprintf(fp, "%d ", list_guest[i].in_danger_area);
		fprintf(fp, "%s ", list_guest[i].apply_in_time, 20);
		fprintf(fp, "%s ", list_guest[i].apply_out_time, 20);
		fprintf(fp, "%s ", list_guest[i].reason, 30);
		fprintf(fp, "%d ", list_guest[i].apply_result);
		fprintf(fp, "%s ", list_guest[i].real_in_time);
		fprintf(fp, "%s\n", list_guest[i].real_out_time);
	}
	err1 = fclose(fp);
}

void administrator()
{
	if (check() == 0)
	{
		return;//密码错误或者姓名错误
	}
	read();
	int end = 1;
	while (end)
	{
		system("cls");
		gotoxy(43, 14);
		printf("1.审批申请");
		gotoxy(43, 16);
		printf("2.查询记录");
		gotoxy(43, 18);
		printf("3.增加管理员");
		gotoxy(43, 20);
		printf("按任意键返回上级菜单");
		hide();
		char ch = _getch();
		switch (ch)
		{
		case '1':
			approve();
			break;
		case '2':
			seek();
			break;
		case '3':
			add();
			break;
		default:
			end = 0;
		}
		system("cls");
	}
}

int check()
{
	gotoxy(43, 12);
	printf("请输入管理员姓名:");
	scanf_s("%s", admin.user_name, 30);
	gotoxy(43, 14);
	printf("请输入密码:");
	scanf_s("%s", admin.password, 30);
	FILE* fp;
	errno_t err2, err1 = fopen_s(&fp, "C:\\Users\\acer\\source\\repos\\system_call\\admin.txt", "r");
	if (err1 != 0)
	{
		system("cls");
		gotoxy(43, 12);
		printf("管理员未注册");
		return 0;
	}
	while (fp != EOF)
	{
		fscanf_s(fp, "%s", list_admin[n].user_name, 30);
		fscanf_s(fp, "%s", list_admin[n].password, 30);
		if (strcmp(list_admin[n].user_name, "") == 0) break;
		n++;
	}
	err2 = fclose(fp);
	//判断输入的管理员是否正确
	for (int i = 0; i < n; i++)
	{
		if (strcmp(admin.user_name, list_admin[i].user_name) == 0 && strcmp(admin.password, list_admin[i].password) == 0) {
			system("cls");
			return 1;
		}
	}
	gotoxy(43, 18);
	printf("管理员账号或密码错误");
	gotoxy(43, 20);
	printf("按任意键返回上一级");
	char ch = _getch();
	return 0;
}

void data_seek()
{
	char data_begin[20] = { '\0' };//查询起始日期
	char data_end[20] = { '\0' };//查询结束日期
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询申请的开始时间(格式:yy/mm/dd/hh/mm):");
	scanf_s("%s", data_begin, 20);
	gotoxy(43, 14);
	printf("请输入查询申请的结束时间(格式:yy/mm/dd/hh/mm):");
	scanf_s("%s", data_end, 20);
	gotoxy(12, 13);
	int sum = 0;
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话          进校事由");
	for (int i = 0; i < m; i++)
	{
		if (strcmp(list_guest[i].apply_in_time, data_begin) >= 0 && strcmp(list_guest[i].apply_out_time, data_end) < 0)
		{
			sum++;
			gotoxy(12, 14 + sum);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 16 + sum);
	printf("该时间段内的申请总数为%d\n", sum);
	gotoxy(43, 17 + sum);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void name_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询申请人的姓名:");
	char temp[20] = { '\0' };
	scanf_s("%s", temp, 20);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (strcmp(list_guest[i].name, temp) == 0)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void id_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询申请人的身份证号:");
	char temp[30] = { '\0' };
	scanf_s("%s", temp, 30);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (strcmp(list_guest[i].id_number, temp) == 0)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void sex_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询申请人的性别(输入1代表男，输入0代表女):");
	int temp_sex = 0;
	scanf_s("%d", &temp_sex);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (list_guest[i].sex == temp_sex);
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void surety_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询担保人的姓名:");
	char temp[20] = { '\0' };
	scanf_s("%s", temp, 20);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (strcmp(list_guest[i].surety_name, temp) == 0)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void telephone_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询申请人的电话:");
	char temp[20] = { '\0' };
	scanf_s("%s", temp, 20);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (strcmp(list_guest[i].telephone, temp) == 0)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void team_seek()
{
	int ans = 0;
	system("cls");
	gotoxy(43, 12);
	printf("请输入查询的类别(输入1代表个人，输入2代表团体):");
	int temp_is_team = 0;
	scanf_s("%d", &temp_is_team);
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话                申请进校时间       申请离校时间         进校事由");
	for (int i = 0; i < m; i++)
	{
		if (list_guest[i].is_team == temp_is_team)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%3d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-20s ", list_guest[i].apply_in_time);
			printf("%-20s ", list_guest[i].apply_out_time);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	gotoxy(43, 17 + ans);
	printf("查询到的总申请为%d", ans);
	gotoxy(43, 19 + ans);
	printf("按任意键返回上一级");
	char ch = _getch();
}

void info_seek()
{
	int end = 1;
	while (end)
	{
		system("cls");
		gotoxy(43, 14);
		printf("请选择查询的人员信息:");
		gotoxy(43, 16);
		printf("1.申请人姓名");
		gotoxy(43, 18);
		printf("2.申请人性别");
		gotoxy(43, 20);
		printf("3.申请人电话");
		gotoxy(43, 22);
		printf("4.申请人身份证号");
		gotoxy(43, 24);
		printf("5.担保人姓名");
		gotoxy(43, 26);
		printf("6.是否为团体");
		gotoxy(43, 28);
		printf("按任意键返回上级菜单");
		hide();
		char ch = _getch();
		switch (ch)
		{
		case '1':
		{
			name_seek();
			break;
		}
		case '2':
		{
			sex_seek();
			break;
		}
		case '3':
		{
			telephone_seek();
			break;
		}
		case '4':
		{
			id_seek();
			break;
		}
		case '5':
		{
			surety_seek();
			break;
		}
		case '6':
		{
			team_seek();
			break;
		}
		default:
			end = 0;
		}
	}
}

void seek()
{
	int end = 1;
	while (end)
	{
		system("cls");
		gotoxy(43, 14);
		printf("请选择查询方式:");
		gotoxy(43, 16);
		printf("1.申请人信息");
		gotoxy(43, 18);
		printf("2.申请日期");
		gotoxy(43, 20);
		printf("按任意键返回上级菜单");
		hide();
		char ch = _getch();
		switch (ch)
		{
		case '1':
			info_seek();
			break;
		case '2':
			data_seek();
			break;
		default:
			end = 0;
		}
	}
}

void approve()
{
	system("cls");
	int ans = 0;//未通过的申请总数
	gotoxy(43, 12);
	printf("审批未自动通过名单:");
	gotoxy(12, 13);
	printf("编号 申请人姓名     申请人性别    申请人电话    ");
	printf("      担保人姓名          担保人电话          进校事由");
	for (int i = 0; i < m; i++)
	{
		if (list_guest[i].apply_result == 2)
		{
			ans++;
			gotoxy(12, 13 + ans);
			printf("%d.    %-20s", i, list_guest[i].name);
			if (list_guest[i].sex == 1) printf("男      ");
			else printf("女     ");
			printf("%-20s ", list_guest[i].telephone);
			printf("%-20s ", list_guest[i].surety_name);
			printf("%-20s ", list_guest[i].surety_phone);
			printf("%-30s ", list_guest[i].reason);
		}
	}
	int end = 1;
	int der2 = 0;//要处理的编号
	int temp = 1;//光标的位置
	while (end) {
		gotoxy(43, 14 + ans + temp);
		temp++;
		printf("请输入要处理的审批编号或输入-1返回上一级:");
		scanf_s("%d", &der2);
		if (list_guest[der2].apply_result == 2 && der2 >= 0)
		{
			gotoxy(43, 14 + ans + temp);
			temp++;
			printf("是否通过[y/n]");
			char ch = '\0';
			scanf_s("\n%c", &ch);
			if (ch == 'y')
			{
				list_guest[der2].apply_result = 1;
				printf("     审批成功！");
			}
			else if (ch == 'n')
			{
				list_guest[der2].apply_result = 0;
				printf("     驳回成功！");
			}
			else printf("    没有按提示输入！");
		}
		else if (der2 == -1)
		{
			write();
			end = 0;
		}
	}
}

void add()
{
	system("cls");
	char add_name[30] = { '\0' }, add_pass[30] = { '\0' };
	gotoxy(43, 12);
	printf("请输入增加管理员的账号");
	scanf_s("%s", add_name, 30);
	gotoxy(43, 14);
	printf("请输入增加管理员的密码");
	scanf_s("%s", add_pass, 30);
	for (int i = 0; i < n; i++)
	{
		if (strcmp(add_name, list_admin[i].user_name) == 0)
		{
			system("cls");
			gotoxy(43, 12);
			printf("该管理员已存在!");
			gotoxy(43, 14);
			printf("按任意键返回上一级");
			char ch = _getch();
			return;
		}
	}
	FILE* fp2;
	errno_t err2, err1 = fopen_s(&fp2, "C:\\Users\\acer\\source\\repos\\system_call\\admin.txt", "a");
	fprintf_s(fp2, "%s\n", add_name);
	fprintf_s(fp2, "%s\n", add_pass);
	err2 = fclose(fp2);
	system("cls");
	gotoxy(43, 12);
	printf("增加成功!");
	gotoxy(43, 14);
	printf("按任意键返回上一级");
	char ch = _getch();
	return;
}

void guest()
{
	int end = 1;
	while (end)
	{
		gotoxy(43, 12);
		printf("1.提出申请");
		gotoxy(43, 14);
		printf("2.登记进入时间");
		gotoxy(43, 16);
		printf("3.登记出校时间");
		gotoxy(43, 18);
		printf("按任意键返回上级菜单");
		hide();
		char ch = _getch();
		switch (ch)
		{
		case '1':
			request();
			break;
		case '2':
			record_in();
			break;
		case '3':
			record_out();
			break;
		default:
			end = 0;
		}
		system("cls");
	}
}

void request()
{
	Guest test;
	system("cls");
	FILE* fp;
	errno_t err1, err2 = fopen_s(&fp, "C:\\Users\\acer\\source\\repos\\system_call\\guest.txt", "a+");
	gotoxy(43, 12);
	printf_s("您是团体进入吗(是——1  否——2)");
	gotoxy(43, 13);
	scanf_s("%d", &guset.is_team);
	fprintf(fp, "%d ", guset.is_team);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入姓名");
	gotoxy(43, 13);
	scanf_s("%s", guset.name, 20);
	fprintf(fp, "%s ", guset.name);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入性别（男——1  女——0）");
	gotoxy(43, 13);
	scanf_s("%d", &guset.sex);
	fprintf(fp, "%d ", guset.sex);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入电话号码");
	gotoxy(43, 13);
	scanf_s("%s", guset.telephone, 20);
	fprintf(fp, "%s ", guset.telephone);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入身份证号码");
	gotoxy(43, 13);
	scanf_s("%s", guset.id_number, 30);
	fprintf(fp, "%s ", guset.id_number);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入您的工作单位");
	gotoxy(43, 13);
	scanf_s("%s", guset.work, 50);
	fprintf(fp, "%s ", guset.work);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入您的车牌号");
	gotoxy(43, 13);
	scanf_s("%s", guset.car_number, 10);
	fprintf(fp, "%s ", guset.car_number);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入您的担保人姓名");
	gotoxy(43, 13);
	scanf_s("%s", guset.surety_name, 20);
	fprintf(fp, "%s ", guset.surety_name);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入您的担保人电话");
	gotoxy(43, 13);
	scanf_s("%s", guset.surety_phone, 20);
	fprintf(fp, "%s ", guset.surety_phone);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入健康码（绿码---1，黄码---2，紫码---3，红码---4）");
	gotoxy(43, 13);
	scanf_s("%d", &guset.health_code);
	fprintf(fp, "%d ", guset.health_code);

	system("cls");
	gotoxy(43, 12);
	printf_s("有无咳嗽（是——1  否——0）");
	gotoxy(43, 13);
	scanf_s("%d", &guset.health_cough);
	fprintf(fp, "%d ", guset.health_cough);

	system("cls");
	gotoxy(43, 12);
	printf_s("最近十四天内是否进过疫区（是——1  否——0）");
	gotoxy(43, 13);
	scanf_s("%d", &guset.in_danger_area);
	fprintf(fp, "%d ", guset.in_danger_area);

	system("cls");
	gotoxy(43, 12);
	printf_s("申请进入时间（按照2021/01/01/12/35  年月日时分的格式输入）");
	gotoxy(43, 13);
	scanf_s("%s", guset.apply_in_time, 20);
	fprintf(fp, "%s ", guset.apply_in_time);

	system("cls");
	gotoxy(43, 12);
	printf_s("申请出校时间（按照2021/01/01/12/35  年月日时分的格式输入）");
	gotoxy(43, 13);
	scanf_s("%s", guset.apply_out_time, 20);
	fprintf(fp, "%s ", guset.apply_out_time);

	system("cls");
	gotoxy(43, 12);
	printf_s("请输入进校事由");
	gotoxy(43, 13);
	scanf_s("%s", guset.reason, 30);
	fprintf(fp, "%s ", guset.reason);
	err1 = fclose(fp);

	system("cls");
	autoapprove();
	gotoxy(43, 14);
	printf_s("请按任意键返回主菜单");
	char ch;
	ch = _getch();
	switch (ch) {
	default: system("cls");
		menu();
	}

}

void autoapprove()
{
	read();
	if (list_guest[m].health_code == 1 && list_guest[m].health_cough == 0 && list_guest[m].in_danger_area == 0)
		list_guest[m].apply_result = 1;
	else
	{
		list_guest[m].apply_result = 2;
	}
	gotoxy(43, 12);
	if (list_guest[m].apply_result == 1)
		printf_s("您的审批已经自动通过，欢迎进入学校！");
	else if (list_guest[m].apply_result == 2)
	{
		printf_s("您的申请还待审批，请联系相关管理员");
	}
}


void record_in()
{
	
	int year = 1970;
	int month = 1;
	int day = 1;
	int month1[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	int month2[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//闰年 
	int hour, min, second, temp = 0;
	int i, j, q, t;//判断条件数
	char rtime;//用于录入时间

	system("cls");
	time_t seconds;
	seconds = time(NULL);


	day = (int)seconds / (24 * 3600);//计算天数，一天24*60*60秒 

	seconds = seconds % (24 * 3600);//当前天的总秒数 
	hour = (int)(seconds / 3600);//计算当前天的小时 
	seconds = seconds % 3600;//分钟的秒数+秒数 
	min = (int)(seconds / 60);//计算当前天的分钟 
	second = (int)(seconds % 60);//当前的秒数 

	//计算年份 
	for (i = day; i > 364; i--)
	{
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)//闰年 
		{
			year = year + 1;
			i = i - 366 + 1;
		}
		else {//非闰年 
			year = year + 1;
			i = i - 365 + 1;
		}
	}

	if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) //闰年 
	{
		if (i < 31)
		{
			month = 1;
			day = i + 1;
		}
		else
		{
			for (q = 0; q < 12; q++)
			{
				temp = month2[q];
				if (temp < i + 1)
				{
					month = q + 1;
					i = i - month2[q];

				}
				else break;
				//break;
			}
			day = i + 1;
			month = month + 1;
		}

	}
	else//非闰年 
	{
		if (i < 31)
		{
			month = 1;
			day = i + 1;
		}
		else
		{
			for (q = 0; q < 12; q++)
			{
				temp = month1[q];
				if (temp < i + 1)
				{
					month = q + 1;
					i = i - month1[q];
					//break;
				}
				else break;
			}
			day = i + 1;
			month = month + 1;

		}
	}

	//日期转换成字符串
	char ryear[20];
	ryear[0] = ((year / 1000) % 10 + '0');
	ryear[1] = ((year / 100) % 10 + '0');
	ryear[2] = ((year / 10) % 10 + '0');
	ryear[3] = (year % 10 + '0');
	ryear[4] = '/';
	ryear[5] = (month / 10 % 10 + '0');
	ryear[6] = (month % 10 + '0');
	ryear[7] = '/';
	ryear[8] = (day / 10 % 10 + '0');
	ryear[9] = (day % 10 + '0');
	ryear[10] = '/';
	ryear[11] = (hour / 10 % 10 + '0');
	ryear[12] = (hour % 10 + '0');
	ryear[13] = '/';
	ryear[14] = (min / 10 % 10 + '0');
	ryear[15] = (min % 10 + '0');
	ryear[16] = '/';
	ryear[17] = '\0';

	char rname[20];
	gotoxy(43, 12);
	printf_s("请输入你的姓名用于检查申请记录");
	gotoxy(43, 13);
	scanf_s("%s", rname, 20);
	read();
	for (t = 0; t <= m; t++) {//匹配输入的姓名和申请记录
		if (strcmp(list_guest[t].name, rname) == 0) {
			for (int i = 0; i < 18; i++) list_guest[t].real_in_time[i] = ryear[i];
			break;
		}
	}
	if (t >= m) {
		gotoxy(43, 14);
		printf_s("您未申请或您的申请未通过");
		gotoxy(43, 16);
		printf_s("请按任意键返回上一级");
		char ch = _getch();
		return ;
	}
	write();
	system("cls");
	gotoxy(43, 12);
	printf_s("欢迎您在 %d/%d/%d/", year, month, day);
	printf_s("%d/%d/%d/  进入学校！", hour, min, second);
	gotoxy(43, 14);
	printf_s("请按任意键退出");
	char ch;
	ch = _getch();
	exit(0);

}

void record_out()
{
	int year = 1970;
	int month = 1;
	int day = 1;
	int month1[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	int month2[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//闰年 
	int hour, min, second, temp = 0;
	int i, j, q, t;//判断条件数
	char rtime;//用于录入时间

	system("cls");
	time_t seconds;
	seconds = time(NULL);


	day = (int)seconds / (24 * 3600);//计算天数，一天24*60*60秒 

	seconds = seconds % (24 * 3600);//当前天的总秒数 
	hour = (int)(seconds / 3600);//计算当前天的小时 
	seconds = seconds % 3600;//分钟的秒数+秒数 
	min = (int)(seconds / 60);//计算当前天的分钟 
	second = (int)(seconds % 60);//当前的秒数 

	//计算年份 
	for (i = day; i > 364; i--)
	{
		if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)//闰年 
		{
			year = year + 1;
			i = i - 366 + 1;
		}
		else {//非闰年 
			year = year + 1;
			i = i - 365 + 1;
		}
	}

	if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) //闰年 
	{
		if (i < 31)
		{
			month = 1;
			day = i + 1;
		}
		else
		{
			for (q = 0; q < 12; q++)
			{
				temp = month2[q];
				if (temp < i + 1)
				{
					month = q + 1;
					i = i - month2[q];

				}
				else break;
				//break;
			}
			day = i + 1;
			month = month + 1;
		}

	}
	else//非闰年 
	{
		if (i < 31)
		{
			month = 1;
			day = i + 1;
		}
		else
		{
			for (q = 0; q < 12; q++)
			{
				temp = month1[q];
				if (temp < i + 1)
				{
					month = q + 1;
					i = i - month1[q];
					//break;
				}
				else break;
			}
			day = i + 1;
			month = month + 1;

		}
	}




	//日期转换成字符串
	char ryear[20];
	ryear[0] = ((year / 1000) % 10 + '0');
	ryear[1] = ((year / 100) % 10 + '0');
	ryear[2] = ((year / 10) % 10 + '0');
	ryear[3] = (year % 10 + '0');
	ryear[4] = '/';
	ryear[5] = (month / 10 % 10 + '0');
	ryear[6] = (month % 10 + '0');
	ryear[7] = '/';
	ryear[8] = (day / 10 % 10 + '0');
	ryear[9] = (day % 10 + '0');
	ryear[10] = '/';
	ryear[11] = (hour / 10 % 10 + '0');
	ryear[12] = (hour % 10 + '0');
	ryear[13] = '/';
	ryear[14] = (min / 10 % 10 + '0');
	ryear[15] = (min % 10 + '0');
	ryear[16] = '/';
	ryear[17] = '\0';

	char rname[20];
	gotoxy(43, 12);
	printf_s("请输入你的姓名用于检查申请记录");
	gotoxy(43, 13);
	scanf_s("%s", rname, 20);
	read();
	for (t = 0; t <= m; t++) {//匹配输入的姓名和申请记录
		if (strcmp(list_guest[t].name, rname) == 0) {
			for (int i = 0; i < 18; i++) list_guest[t].real_out_time[i] = ryear[i];
			break;
		}
	}
	if (t >= m) {
		gotoxy(43, 14);
		printf_s("您未申请或您的申请未通过");
		gotoxy(43, 16);
		printf_s("请按任意键返回上一级");
		char ch = _getch();
		return;
	}
	write();
	system("cls");
	gotoxy(43, 12);
	printf_s("您在 %d/%d/%d/", year, month, day);
	printf_s("%d/%d/%d/  离开学校！", hour, min, second);
	gotoxy(43, 14);
	printf_s("请按任意键退出");
	char ch;
	ch = _getch();
	exit(0);
}
